<template>
  <div>child3组件 - {{ count }} - <button @click="fn">btn</button></div>
</template>

<script>
// mapActions用于简化actions的写法
import { mapActions } from "vuex";

export default {
  computed: {
    count() {
      return this.$store.state.count;
    },
  },
  methods: {
    // 映射，将仓库的actions的函数映射到组件的props里面
    ...mapActions(["addAsync"]),
    fn() {
      // 使用dispatch方法去触发actions的函数
      // this.$store.dispatch("addAsync", { num: 1 });

      this.addAsync({ num: 1 });
    },
  },
};
</script>
